var page = 1;
var pagesize = 20;
var status = 1;

$(function (){
	$(document)
		.on('click','._dropdown_menu_li',function (){
			var obj = $(this);
			// alert(obj.attr('data-name'));
			var name = obj.attr('data-name');
			status = obj.attr('data-status')

			$('._text_status').html(name);
			geelist({page:page,pagesize:pagesize,status:status});

		})
		.on('click','._import_submit',function (){
			location.href="/Structure/importin.html";
		})

		;

	//列表初始化
	getlist();

	//注册日期格式化方法
	template.helper('dateFormat', dateFormat);

	//生成api前，判断是否有导入数据
	$('._api_button').click(function (){
		var obj = $(this);
		var status = obj.attr('data-status');
		if(status){
			location.href="/Modelapi/add.html";
		}else{
			$('.bs-example-modal').modal();	
		}
		
	});

});

//获取数据列表
function getlist(option){
	var default_option = {
	    page : 1,//当前页码
	    pagesize : pagesize,
	    status:1//类型筛选
	  }
	option = $.extend({},default_option,option);
	$.ajax({
	    url:'/Modelapi/ajaxList.html',
	    type:'POST',
	    dataType:'json',
	    async:true,
	    data:option,
	    success:function (req){
	      if(req.status==200){
//	      	console.log(req.data);
	        //渲染数据
	        var html = template("list_template", req.data);

	        document.getElementById("table_content").innerHTML = html;

	        // //获取分页html代码
	        // var page = _37degree_setpage(req.data.page,req.data.totalpage);//当前页码，总页数
	        // $('._page_info').html(page);

	      }else{
	        show_msg({msg:req.msg,type:'error',time:2000});
	      }
	      return false;
	    },
	    error:function (){
	      show_msg({msg:'系统异常',type:'error',time:2000});
	    }
  });

}

//切换分页时
function gotopage(current_page){  
  //获取分页数据
  getApiList({page:current_page,pagesize:pagesize,status:status});
}